<template>
  <div class="dataBase">
    <ContentWrap>
      <el-form
        ref="formRef"
        :model="searchValue"
        class="flex flex-wrap"
        v-if="infoShowList && infoShowList.length"
      >
        <el-col :span="6" v-if="infoShowList[5]?.query">
          <el-form-item class="px-3" label="数据标准" prop="template">
            <el-select
              v-model="searchValue.template"
              clearable
              placeholder="请选择数据标准"
              filterable
              @change="templateChange"
            >
              <el-option
                v-for="(template, templateIndex) in templateList"
                :key="templateIndex"
                :label="template.dataStandardName"
                :value="template.id"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[0]?.query">
          <el-form-item class="px-3" label="资产id" prop="id">
            <ns-input v-model="searchValue.id" clearable placeholder="请输入资产id" />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[1]?.query">
          <el-form-item class="px-3" label="文件名称" prop="fileName">
            <ns-input v-model="searchValue.fileName" clearable placeholder="请输入文件名称" />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[2]?.query">
          <el-form-item class="px-3" label="文件类型" prop="fileType">
            <ns-input v-model="searchValue.fileType" clearable placeholder="请输入文件类型" />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[3]?.query">
          <el-form-item class="px-3" label="文件大小" prop="fileSize">
            <ns-input v-model="searchValue.fileSize" clearable placeholder="请输入文件大小" />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[4]?.query">
          <el-row>
            <el-col :span="16">
              <el-form-item class="px-3" label="文件指纹" prop="figureType">
                <el-select placeholder="请选择指纹类型" v-model="searchValue.figureType">
                  <el-option
                    v-for="item in figureTypes"
                    :label="item.name"
                    :value="item.name"
                    :key="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="" prop="figureValue">
                <ns-input
                  v-model="searchValue.figureValue"
                  clearable
                  placeholder="请输入指纹内容"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="6" v-if="infoShowList[14]?.query">
          <el-form-item class="px-3" label="文件来源" prop="source">
            <el-select v-model="searchValue.source" clearable placeholder="请选择文件来源">
              <el-option label="手动上传" :value="3" />
              <el-option label="转储文件" :value="4" />
              <el-option label="监测平台" :value="5" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[6]?.query">
          <el-form-item class="px-3" label="归属机构" prop="deptId">
            <el-cascader
              v-model="searchValue.deptId"
              clearable
              placeholder="请选择归属机构"
              :options="options"
              :props="cascaderProps"
              filterable
              :filter-method="sysFilterMethod"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[7]?.query">
          <el-form-item class="px-3" label="归属系统" prop="sysId">
            <el-cascader
              v-model="searchValue.sysId"
              placeholder="请选择归属系统"
              :props="systemCascaderProps"
              :options="systemList"
              filterable
              clearable
              :filter-method="sysFilterMethod"
          /></el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[8]?.query">
          <el-form-item class="px-3" label="分类" prop="classification">
            <el-cascader
              v-model="searchValue.classification"
              placeholder="请选择分类"
              :props="classificationCascaderProps"
              :options="classificationList"
              filterable
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[9]?.query">
          <el-form-item class="px-3" label="分级" prop="level">
            <el-select v-model="searchValue.level" clearable placeholder="请选择分级">
              <el-option
                v-for="(level, levelIndex) in levelList"
                :key="levelIndex"
                :label="level.levelName"
                :value="level.levelCode"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[10]?.query">
          <el-form-item class="px-3" label="保密期限" prop="institutionFiled3">
            <ns-input
              v-model="searchValue.institutionFiled3"
              clearable
              placeholder="请选择保密期限"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[11]?.query">
          <el-form-item class="px-3" label="定密日期" prop="filed1Range">
            <el-date-picker
              style="width: 90%"
              v-model="searchValue.filed1Range"
              type="datetimerange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="YYYY-MM-DD HH:mm:ss"
              date-format="YYYY/MM/DD"
              time-format="hh:mm:ss"
              value-format="YYYY-MM-DD HH:mm:ss"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[12]?.query">
          <el-form-item class="px-3" label="解密日期" prop="filed2Range">
            <el-date-picker
              style="width: 90%"
              v-model="searchValue.filed2Range"
              type="datetimerange"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              format="YYYY-MM-DD HH:mm:ss"
              date-format="YYYY/MM/DD"
              time-format="hh:mm:ss"
              value-format="YYYY-MM-DD HH:mm:ss"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[13]?.query">
          <el-form-item class="px-3" label="到期后变更等级" prop="deadlineLevel">
            <el-select
              v-model="searchValue.deadlineLevel"
              clearable
              placeholder="请选择到期后变更等级"
            >
              <el-option
                v-for="(level, levelIndex) in levelList"
                :key="levelIndex"
                :label="level.levelName"
                :value="level.levelCode"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[15]?.query">
          <el-form-item class="px-3" label="分级进度" prop="process">
            <el-input
              :min="0"
              :max="100"
              v-model="searchValue.process"
              clearable
              placeholder="请输入分级进度"
              @input="handleInput"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[16]?.query">
          <el-form-item class="px-3" label="自动分级状态" prop="autoClassStatus">
            <el-select v-model="searchValue.autoClassStatus" clearable placeholder="请选择分级状态">
              <el-option
                v-for="(item, index) in autoClassStatusMap"
                :key="index"
                :label="item[1]"
                :value="item[0]"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[17]?.query">
          <el-form-item class="px-3" label="自动分级时间" prop="autoClassificationTime">
            <el-date-picker
              v-model="searchValue.autoClassificationTime"
              type="datetime"
              value-format="YYYY-MM-DD HH:mm:ss"
              placeholder="选择日期时间"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6" v-if="infoShowList[18]?.query">
          <el-form-item class="px-3" label="审核状态" prop="auditStatus">
            <el-select v-model="searchValue.auditStatus" clearable placeholder="请选择审核状态">
              <el-option label="审核中" :value="1" />
              <el-option label="审核通过" :value="2" />
              <el-option label="审核拒绝" :value="3" />
              <el-option label="待处理" :value="0" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item class="px-3" label="是否已分级">
            <el-select v-model="searchValue.isLevel" clearable placeholder="请选择是否已分级">
              <el-option label="已分级" :value="true" />
              <el-option label="未分级" :value="false" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item class="px-3" label="是否查询关联标准" prop="isSearchSon">
            <el-select
              v-model="searchValue.isSearchSon"
              clearable
              placeholder="请选择是否查询关联标准"
            >
              <el-option label="是" :value="true" />
              <el-option label="否" :value="false" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-form>
      <el-row>
        <el-col :span="24" class="text-right">
          <el-button @click="searchReset" plain>重置</el-button>
          <el-button @click="search" plain>搜索</el-button>
        </el-col>
      </el-row>
    </ContentWrap>
    <ContentWrap>
      <el-form-item>
        <el-button type="primary" @click="uploadScan('2')" v-hasPermi="['pending:file:scan']">
          新增</el-button
        >
        <el-button type="primary" @click="uploadScan('1')" v-hasPermi="['pending:file:smartScan']">
          新增（智能）</el-button
        >
        <el-button
          type="primary"
          :disabled="ids.length == 0"
          @click="openAutoClassification"
          v-hasPermi="['pending:file:autoClass']"
        >
          智能分类分级
        </el-button>
        <el-button
          type="primary"
          :disabled="ids.length == 0"
          @click="handleUpdateList"
          v-hasPermi="['pending:file:listClass']"
        >
          批量修改
        </el-button>
        <el-button
          type="primary"
          :disabled="ids.length == 0"
          @click="handleAuditList"
          v-hasPermi="['pending:file:audit']"
        >
          批量提交审核
        </el-button>
        <el-button
          type="primary"
          :disabled="ids.length == 0"
          @click="handleDownloadList"
          v-hasPermi="['pending:file:download']"
        >
          下载
        </el-button>
        <el-button @click="handleExport" v-hasPermi="['pending:file:export']"> 导出</el-button>
        <el-button @click="handleImport" v-hasPermi="['pending:file:import']"> 导入</el-button>
        <el-button @click="handleEditInfo" v-hasPermi="['pending:file:showInfo']"
          >信息展示设置</el-button
        >
        <el-button
          :disabled="ids.length == 0"
          type="danger"
          @click="delList"
          v-hasPermi="['pending:file:delete']"
        >
          删除
        </el-button>
      </el-form-item>
      <AsyncTable
        v-bind="tableInfo"
        ref="tableRef"
        :fetchData="fetchData"
        @selection-change="changeTable"
      />
    </ContentWrap>
    <BatchSubmitResult
      :dialogVisible="dialogVisible"
      v-if="dialogVisible"
      :info="batchResult"
      @close="dialogVisible = false"
    />
    <InfoShow ref="dialogRef" @success="getInfoShowConf" />
    <ImportForm ref="importFormRef" @success="search" />
    <!-- 批量修改弹窗 -->
    <UpdateListLevel ref="updateListRef" @success="search" type="outside" />
  </div>
</template>

<script setup lang="tsx">
import { sysFilterMethod } from '@/utils/selectFilter'
import UpdateListLevel from '@/views/asset/assetList/databaseList/detail/components/updateListLevel.vue'
import ImportForm from '@/views/asset/assetList/components/ImportForm.vue'
import BatchSubmitResult from '@/views/asset/components/BatchSubmitResult.vue'
import { ElMessage } from 'element-plus'
import AsyncTable from '@/components/AsyncTable'
import { useRouter } from 'vue-router'
import * as api from '@/api/dataSourceManage/index'
import {
  getDataBaseList,
  pendingAssetDel,
  pendingAssetListDel,
  assetMessageExportExcelFile,
  fileAuditBatch,
  fileCancel,
  clonePeddingFile
} from '@/api/assetList/index'
import { getSimpleDeptList } from '@/api/system/dept'
import { handleTree } from '@/utils/tree'
import { levelPage } from '@/api/strategyManage/level/index'
import { getSimpleSystemList } from '@/api/asset/taskManage'
import dayjs from 'dayjs'
import { ComponentInternalInstance, getCurrentInstance } from 'vue'
import {
  renderFinger,
  sourceRender,
  renderClassification,
  renderLevel,
  autoClassStatusRender
} from '@/utils/commonRender'
import download from '@/utils/download'
import * as infoShowApi from '@/api/infoShow/index'
import InfoShow from '@/views/assetManage/components/infoShow.vue'
import { dataStandardsPage } from '@/api/dataStandards/standards/index'
import { dataClassificationTree } from '@/api/dataStandards/classification/index'
import { autoClassStatusMap, sourceMap } from '@/utils/dict'
import { checkPermi } from '@/utils/permission'
import { fileExchange } from '@/api/infra/file'
import { getFingerType } from '@/api/develop/featureLibrary/fingerprint'
import axios from 'axios'
const message = useMessage() // 消息弹窗
const systemList = ref([
  {
    id: 1,
    name: '系统1',
    children: [
      { id: 11, name: '子系统1' },
      { id: 12, name: '子系统2' },
      { id: 13, name: '子系统3' }
    ]
  }
])
const dialogVisible = ref(false)
const batchResult = ref([])
const classificationCascaderProps = ref({
  checkStrictly: true,
  label: 'text',
  value: 'id',
  children: 'children',
  emitPath: false
})
const systemCascaderProps = {
  checkStrictly: true,
  label: 'value',
  value: 'id',
  children: 'children',
  emitPath: false
}
const tableRef = ref()
const formRef = ref()
const { proxy } = getCurrentInstance() as ComponentInternalInstance
const router = useRouter()
const ids = ref<string[]>([])
const items = ref<any[]>([])
const cascaderProps = ref({
  checkStrictly: true,
  label: 'name',
  value: 'id',
  children: 'children',
  emitPath: false
})
const options = ref<Tree[]>([])
const assetTypeList = ref([])

/**
 * @description: 选取列表时获取列表id
 * @param {*} val
 */
const changeTable = (val) => {
  ids.value = []
  items.value = []
  val.map((item) => {
    ids.value.push(item.id)
    items.value.push(item)
  })
}
const searchReset = () => {
  formRef.value.resetFields()
  tableRef.value.resetPage()
  tableRef.value.fetchData()
}

const searchValue = ref({
  id: '',
  fileName: '',
  fileType: '',
  level: '',
  importance: '',
  process: undefined,
  sysId: '',
  deptId: '',
  isLevel: '',
  auditStatus: '',
  isSearchSon: '',
  institutionFiled3: '',
  filed2Range: '',
  filed1Range: '',
  deadlineLevel: '',
  autoClassStatus: '',
  classification: '',

  figureType: '', // 文件指纹类型
  figureValue: '' // 文件指纹数据
})

// 所有指纹类型
const figureTypes = ref([])
/** 获取指纹类型 */
async function getTypes() {
  const res = await getFingerType()
  figureTypes.value = Object.entries(res).map(([key, value]) => {
    return {
      name: value as string,
      value: key
    }
  })
}

const allSelect = ref(false)
const search = () => {
  tableRef.value.resetPage()
  tableRef.value.fetchData()
}

function checkSelectable(row) {
  return row.auditStatus != '1'
}

//根据数据标准筛选分类
const templateChange = () => {
  if (searchValue.value.template) {
    classificationList.value = classificationListCopy.value.filter(
      (item) => item.id == searchValue.value.template
    )
    searchValue.value.classification = ''
  } else {
    classificationList.value = classificationListCopy.value
  }
}

const tableInfo = reactive({
  columns: [
    {
      type: 'selection',
      selectable: checkSelectable
    },
    { label: '资产id', prop: 'id', width: '200px' },
    { label: '文件名称', prop: 'fileName', width: '150px' },
    { label: '文件类型', width: '100px', prop: 'fileType' },
    { label: '文件大小', width: '100px', prop: 'fileSize' },
    { label: '文件指纹', width: '150px', render: renderFinger },
    {
      label: '数据标准',
      prop: 'templateName',
      width: '100px'
    },
    {
      label: '归属机构',
      width: '100px',
      prop: 'deptName'
    },
    {
      label: '归属系统',
      width: '100px',
      prop: 'sysName'
    },
    {
      label: '分类',
      render: renderClassification,
      width: '150px'
    },
    {
      label: '分级',
      render: renderLevel,
      width: '150px'
    },
    {
      label: '保密期限',
      width: '100px',
      prop: 'institutionFiled3'
    },
    {
      label: '定密日期',
      prop: 'field1',
      width: '200px'
    },
    {
      label: '解密日期',
      prop: 'field2',
      width: '200px'
    },
    {
      label: '到期后变更等级',
      width: '150px',
      prop: 'deadlineLevelName'
    },
    { label: '文件来源', render: sourceRender, width: '100px' },
    {
      label: '分级进度',
      width: '100px',
      render: ({ row }) => {
        return (
          <>
            <span>{row.process}%</span>
          </>
        )
      }
    },
    {
      label: '自动分级状态',
      width: '120px',
      render: autoClassStatusRender
    },
    {
      label: '自动分级时间',
      prop: 'autoClassificationTime',
      width: '200px'
    },
    {
      label: '创建时间',
      prop: 'createTime',
      width: '200px'
    },
    {
      label: '审核状态',
      width: '100px',
      render: ({ row }) => {
        return (
          <>
            <span>{row.auditStatusValue || '待处理'}</span>
          </>
        )
      }
    },

    {
      label: '操作项',
      width: '300px',
      fixed: 'right',
      render: ({ row }) => {
        return (
          <>
            {checkPermi(['pending:file:clone']) && (
              <el-button
                link
                type="primary"
                onClick={() => {
                  cloneRow(row.id)
                }}
              >
                克隆
              </el-button>
            )}
            {checkPermi(['pending:file:audit']) && (
              <>
                {row.auditStatusValue === '审核中' ? (
                  <el-button
                    link
                    type="primary"
                    onClick={() => {
                      withdrawProcess(row)
                    }}
                  >
                    撤回
                  </el-button>
                ) : (
                  <el-button
                    link
                    type="primary"
                    onClick={() => {
                      submitProcess(row)
                    }}
                  >
                    审核申请
                  </el-button>
                )}
              </>
            )}
            {checkPermi(['pending:file:edit']) &&
              (row.auditStatusValue === '待处理' ||
                row.auditStatusValue === '审核拒绝' ||
                row.auditStatusValue === '--' ||
                !row.auditStatusValue) && (
                <el-button
                  link
                  type="primary"
                  onClick={() => {
                    gotoDetail(row)
                  }}
                >
                  编辑
                </el-button>
              )}

            {checkPermi(['pending:file:history']) && (
              <el-button
                link
                type="primary"
                onClick={() => {
                  goHistory(row)
                }}
              >
                历史记录
              </el-button>
            )}
            {checkPermi(['pending:file:delete']) &&
              (row.auditStatusValue === '待处理' ||
                row.auditStatusValue === '审核拒绝' ||
                row.auditStatusValue === '--' ||
                !row.auditStatusValue) && (
                <ns-button
                  link
                  style="margin-left:6px"
                  type="danger"
                  confirm
                  onClick={() => {
                    del(row)
                  }}
                >
                  删除
                </ns-button>
              )}
          </>
        )
      }
    }
  ],
  data: []
})

const del = (row) => {
  pendingAssetDel(row.id).then((response) => {
    tableRef.value.fetchData()
    ElMessage.success('提交成功')
  })
}

const cloneRow = async (id) => {
  const data = await proxy.$modal.confirm(`确定要克隆选择的资产吗？`)
  if (data) {
    await clonePeddingFile({ id })
    tableRef.value.resetPage()
    tableRef.value.fetchData()
  }
}

// 使用正则表达式只允许输入0-9的数字
function handleInput(value) {
  const filteredValue = value.replace(/[^0-9]/g, '')

  if (filteredValue !== searchValue.value.process) {
    searchValue.value.process = filteredValue
  }
}

const pageParams = ref({
  page: 1,
  pageSize: 10
})
const fetchData = async ({ page, pageSize }) => {
  pageParams.value = {
    page,
    pageSize
  }
  const { data, count } = await getDataBaseList({
    page,
    pageSize,
    isSingle: true,
    dataType: 'file',
    submitStatus: '1',
    isWait: true,
    ...searchValue.value
  })
  return { data, count }
}
const gotoDetail = (row) => {
  proxy?.$Drawer({
    params: {
      ...row,
      type: row.handClassificationName ? `人工` : row.classificationName ? `自动` : '--',
      callBack: () => {
        tableRef.value.resetPage()
        tableRef.value.fetchData()
      }
    },
    title: `分级分类`,
    size: '40%',
    component: import('@/views/asset/assetList/databaseList/detail/components/grade.vue')
  })
}

const goHistory = (row) => {
  router.push({
    path: '/assetManage/fileHistory',
    query: {
      id: row.id,
      dataType: 'file'
    }
  })
}

/** 添加/修改操作 */
const dialogRef = ref()
const handleEditInfo = () => {
  dialogRef.value.open('5')
}

const openAutoClassification = () => {
  proxy?.$Drawer({
    params: {
      ids: ids.value,
      callBack: () => {
        tableRef.value.resetPage()
        tableRef.value.fetchData()
      }
    },
    title: `添加分级对象`,
    size: '50%',
    component: import('@/views/asset/assetList/components/autoClassification.vue')
  })
}

// 批量修改
const updateListRef = ref()
const handleUpdateList = () => {
  updateListRef.value.open(ids.value, 'showAudit')
}

// 批量提交审核
const handleAuditList = async () => {
  await message.confirm('确定将所选记录提交审核')
  const data = items.value.map((item) => {
    return {
      assetId: item.id,
      assetType: item.dataType,
      deptId: item.deptId,
      sysId: item.sysId
    }
  })
  const res = await fileAuditBatch(data)
  if (res) {
    message.success('操作成功')
    tableRef.value.fetchData()
    batchResult.value = res || []
    dialogVisible.value = true
  }
}

// 下载文件
const handleDownloadList = async () => {
  for (const item of items.value) {
    // window.open(item.absolutePath)
    if (item.storagePath) {
      await getFilePath(item.storagePath, item.fileName)
    } else {
      message.warning(`${item.fileName}的下载地址为空`)
    }
  }
}

// 获取文件下载地址
const getFilePath = async (storagePath, fileName) => {
  const data = await fileExchange(storagePath)
  if (data == '500') {
    message.warning('文件未保存或已被清理')
    return
  }
  await axios.get(data).then(async (response) => {
    if (!response.data.code) {
      const url = document.createElement('a')
      url.download = fileName
      url.href = data
      url.style.display = 'none'
      document.body.appendChild(url)
      url.click()
      document.body.removeChild(url)
    } else {
      ElMessage.error('文件未保存或已被清理')
    }
  })
  return new Promise((resolve) => setTimeout(resolve, 500))
}

const exportLoading = ref(true)
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await assetMessageExportExcelFile({
      ...pageParams.value,
      ...searchValue.value,
      dataType: 'file',
      submitStatus: '1',
      isWait: true,
      isSingle: true,
      ids: ids.value
    })
    download.excel(data, '待确认文件资产.xlsx')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

const importFormRef = ref()
const handleImport = () => {
  importFormRef.value.open()
}

//扫描文件
const uploadScan = (isSmart) => {
  proxy?.$Drawer({
    title: '文件新增',
    component: import('./scanFile.vue'),
    size: '80%',
    params: {
      submitStatus: '1',
      isSmart: isSmart,
      callBack: (data: any) => {
        tableRef.value.resetPage()
        tableRef.value.fetchData()
      }
    }
  })
}
//上传文件
const uploadFile = () => {
  proxy?.$Drawer({
    title: '文件添加',
    component: import('@/views/asset/assetList/fileList/components/uploadFile.vue'),
    size: '50%',
    params: {
      submitStatus: '1',
      callBack: () => {
        tableRef.value.resetPage()
        tableRef.value.fetchData()
      }
    }
  })
}

// // 分类分级
// const execClassification = (data) => {
//   proxy?.$Drawer({
//     title: '设计分级策略',
//     component: import('@/views/asset/assetList/components/execClassification.vue'),
//     size: '70%',
//     params: {
//       ids: data.map((item) => item.id),
//       objectType: 3,
//       callBack: (data: any) => {
//         tableRef.value.resetPage()
//         tableRef.value.fetchData()
//       }
//     }
//   })
// }

const delList = () => {
  proxy?.$modal
    .confirm(`确定要删除所选资产吗？`)
    .then(() => {
      pendingAssetListDel(ids.value).then((response) => {
        tableRef.value.fetchData()
        ElMessage.success('删除成功')
      })
    })
    .catch(() => {})
}

const withdrawProcess = (row) => {
  proxy?.$modal
    .confirm(`确定要撤回该流程吗？`)
    .then(async () => {
      await fileCancel({ processInstanceId: row.processInstanceId })
      message.success('操作成功！')
      tableRef.value.resetPage()
      tableRef.value.fetchData()
    })
    .catch(() => {})
}
const submitProcess = (row) => {
  proxy?.$Drawer({
    params: {
      ...row,
      type: row.handClassificationName ? `人工` : row.classificationName ? `自动` : '--',
      processType: 'file',
      callBack: () => {
        tableRef.value.resetPage()
        tableRef.value.fetchData()
      }
    },
    title: `提交审核`,
    size: '40%',
    component: import('../../components/process.vue')
  })
}

const levelList = ref([])
const getLevelList = async () => {
  const { data } = await levelPage({ page: 1, pageSize: 999 })
  levelList.value = data
}

const getSystemList = async () => {
  const data = await getSimpleSystemList({})
  systemList.value = handleTree(data, 'id', 'pid')
}

// 获取部门
const getDept = () => {
  getSimpleDeptList().then((res) => {
    options.value = res
  })
}

// 获取资产类型
const getAssetType = () => {
  api.getAssetTypeList({ datasourceType: 1 }).then((res) => {
    assetTypeList.value = res
  })
}

// 数据标准
const templateList = ref([])
const getTemplateList = async () => {
  const { data } = await dataStandardsPage({ page: 1, pageSize: 999, type: 0, status: '1' })
  templateList.value = data
}

// 获取信息展示
const infoShowList = ref([])
const getInfoShowConf = async () => {
  const data = await infoShowApi.infoShowList({
    type: '5',
    language: location.href.indexOf('/en/') >= 0 ? 'en' : ''
  })
  infoShowList.value = data || []
  data.forEach((item, index) => {
    tableInfo.columns[index + 1].hide = item.show === 0 ? true : false
  })
}

// 分类下拉
const classificationList = ref([])
const classificationListCopy = ref([])
const getClassificationList = async () => {
  const data = await dataClassificationTree({ type: 0 })
  classificationList.value = traverseTree(data)
  classificationListCopy.value = traverseTree(data)
}
function traverseTree(data) {
  const updatedTree = []
  for (let i = 0; i < data.length; i++) {
    const node = data[i] // 创建新节点并添加 disable 属性
    if (node.pid == '-1') {
      node.disabled = true
    }
    updatedTree.push(node)
    if (node.children && node.children.length > 0) {
      node.children = traverseTree(node.children) // 递归遍历子节点并更新子树结构
    }
  }
  return updatedTree
}

onMounted(() => {
  getSystemList()
  getLevelList()
  getDept()
  getAssetType()
  getTemplateList()
  getInfoShowConf()
  getClassificationList()
  getTypes()
})
</script>

<style lang="scss">
.dataBase {
  .el-dropdown-link {
    cursor: pointer;
    color: var(--el-color-primary);
    display: inline-flex;
    align-items: center;
    line-height: 23px;
    padding-left: 12px;
  }
  .el-form .el-select {
    width: 100%;
  }
  :deep(.hide-expand .cell) {
    display: none;
  }
  :deep(.el-form .el-cascader) {
    width: 100%;
  }
  :deep(.operate-btn .el-button.is-text) {
    padding: 0 10px 0 0;
  }
  .el-dropdown-link:focus {
    outline: none;
  }
}
</style>
